Clover coverage report - Enterprise Web Services - 1.0
Coverage timestamp: Mon May 30 2005 17:10:32 CEST
file stats: LOC: 100   Methods: 5
NCLOC: 61   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
AbstractWriter.java 70% 84% 100% 82.5%
coverage coverage
 1   
 /*
 2   
  * Copyright 2001-2004 The Apache Software Foundation.
 3   
  * 
 4   
  * Licensed under the Apache License, Version 2.0 (the "License");
 5   
  * you may not use this file except in compliance with the License.
 6   
  * You may obtain a copy of the License at
 7   
  * 
 8   
  *      http://www.apache.org/licenses/LICENSE-2.0
 9   
  * 
 10   
  * Unless required by applicable law or agreed to in writing, software
 11   
  * distributed under the License is distributed on an "AS IS" BASIS,
 12   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13   
  * See the License for the specific language governing permissions and
 14   
  * limitations under the License.
 15   
  */
 16   
 
 17   
 package org.apache.geronimo.ews.ws4j2ee.toWs;
 18   
 
 19   
 import org.apache.commons.logging.Log;
 20   
 import org.apache.commons.logging.LogFactory;
 21   
 import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext;
 22   
 
 23   
 import java.io.File;
 24   
 import java.io.FileWriter;
 25   
 import java.io.IOException;
 26   
 import java.io.PrintWriter;
 27   
 
 28   
 /**
 29   
  * <p>This is a conveniance class to wite the Writers</p>
 30   
  *
 31   
  * @author Srinath Perera(hemapani@opensource.lk)
 32   
  */
 33   
 
 34   
 public abstract class AbstractWriter implements Writer {
 35   
     /**
 36   
      * <p>this parameter act as a mediator, It contains all the information
 37   
      * this will be passed to the each writer. This will make sure
 38   
      * even if the information that should passed around it will keep
 39   
      * method signatures intact.</p>
 40   
      */
 41   
     protected static Log log =
 42   
             LogFactory.getLog(AbstractWriter.class.getName());
 43   
     protected J2EEWebServiceContext j2eewscontext;
 44   
     /* this is used to write the file */
 45   
     protected PrintWriter out;
 46   
     private String fileName;
 47   
     private boolean verbose;
 48   
 
 49  47
     public AbstractWriter(J2EEWebServiceContext j2eewscontext, String filename)
 50   
             throws GenerationFault {
 51  47
         this.j2eewscontext = j2eewscontext;
 52  47
         this.fileName = filename;
 53  47
         verbose = j2eewscontext.getMiscInfo().isVerbose();
 54   
     }
 55   
 
 56   
     protected abstract void writeCode() throws GenerationFault;
 57   
 
 58  47
     protected final void prepare() throws GenerationFault {
 59  47
         try {
 60  47
             File file = new File(this.fileName);
 61  47
             if (verbose) {
 62  0
                 log.info("genarating ... " + file.getAbsolutePath());
 63   
             }
 64  47
             if (!isOverWrite() && file.exists()) {
 65  2
                 out = null;
 66  2
                 if (verbose) {
 67  0
                     log.info("the file already exists .. tool will not overwrite it ");
 68   
                 }
 69   
             } else {
 70  45
                 File parent = file.getParentFile();
 71  45
                 if (parent != null)
 72  45
                     parent.mkdirs();
 73  45
                 file.createNewFile();
 74  45
                 out = new PrintWriter(new FileWriter(file, false));
 75   
             }
 76   
         } catch (IOException e) {
 77  0
             log.error(e);
 78  0
             throw GenerationFault.createGenerationFault(e);
 79   
         }
 80   
     }
 81   
 
 82  47
     protected final void cleanUp() throws GenerationFault {
 83  47
         if (out != null)
 84  45
             out.close();
 85   
     }
 86   
 
 87  45
     protected boolean isOverWrite() {
 88  45
         return true;
 89   
     }
 90   
 
 91  47
     public final void write() throws GenerationFault {
 92  47
         try {
 93  47
             prepare();
 94  47
             writeCode();
 95   
         } finally {
 96  47
             cleanUp();
 97   
         }
 98   
     }
 99   
 }
 100